package com.hdcx.Minfresh.adapter;


import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hdcx.Minfresh.R;
import com.hdcx.Minfresh.bean.MyPointWrapper;
import com.hdcx.Minfresh.holder.MainHolder;

/**
 * Created by Administrator on 2016/11/9.
 */

public class MineMyPointAdapter extends RecyclerView.Adapter<MineMyPointAdapter.PointHolder> {
    FragmentActivity mActivity;
    MyPointWrapper data;

    public MineMyPointAdapter(FragmentActivity mActivity) {
        this.mActivity = mActivity;
    }

    @Override
    public PointHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        LayoutInflater layoutInflater = LayoutInflater.from(mActivity);
        if (viewType == 0) {
            view = layoutInflater.inflate(R.layout.item_fragment_point_one, parent, false);
        } else {
            view = layoutInflater.inflate(R.layout.item_fragment_point_two, parent, false);
        }
        return new PointHolder(view);
    }

    @Override
    public void onBindViewHolder(PointHolder holder, int position) {
       if(position==0){
           holder.tv_score.setText(data.getScore().equals("")?"0":data.getScore());
       }else{
           holder.tv_content.setText(data.getList().get(position-1).getNote());
           holder.tv_point.setText(data.getList().get(position-1).getCode().equals("add")?"+":"-"+data.getList().get(position).getValue());
           holder.tv_time.setText(data.getList().get(position-1).getAdd_time());
       }

    }

    @Override
    public int getItemCount() {
        if (data == null || data.getList() == null) {
            return 0;
        }
        return data.getList().size() + 1;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    public class PointHolder extends RecyclerView.ViewHolder {
        public TextView tv_score, tv_content, tv_time, tv_point;

        public PointHolder(View itemView) {
            super(itemView);
            tv_score = (TextView) itemView.findViewById(R.id.tv_score);
            tv_content = (TextView) itemView.findViewById(R.id.tv_content);
            tv_time = (TextView) itemView.findViewById(R.id.tv_time);
            tv_point = (TextView) itemView.findViewById(R.id.tv_point);

        }
    }

    public void setData(MyPointWrapper data) {
        this.data = data;
        notifyDataSetChanged();
    }
}
